package com.zl.easybuy.web;

import com.zl.easybuy.exception.EasyBuyException;
import com.zl.easybuy.vo.ResultCode;
import com.zl.easybuy.vo.ResultVO;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 异常处理器
 */
@ControllerAdvice  //对Controller类进行增强: 使用AOP技术
public class GlobeExceptionHandler {

   @ExceptionHandler(EasyBuyException.class)  //表示该方法处理那种类型的异常, 该方法只处理EasyBuyException异常
   @ResponseBody
   public ResultVO handeException(Exception e){
       ResultCode.FAIl.setMsg(e.getMessage());
        return ResultVO.returnFail(ResultCode.FAIl);
   }
}
